package com.wisewin.circle.service;

import com.wisewin.circle.config.dto.ResultDTO;
import com.wisewin.circle.config.dto.ResultDTOBuilder;
import com.wisewin.circle.dao.UserShieldDAO;
import com.wisewin.circle.entity.db.UserShieldDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserShieldService {

    @Autowired
    private UserShieldDAO userShieldDAO;

    // 添加不看谁
    public ResultDTO addUserShield(UserShieldDO userShieldDO){
        if(userShieldDO.getShieldUserId() == null){
            return ResultDTOBuilder.failure("1", "参数有误", null);
        }
        // 不是本人操作
        if(userShieldDO.getShieldUserId() != userShieldDO.getUserId()){
            UserShieldDO userShieldOld = userShieldDAO.queryUserShieldById(userShieldDO);
            if(userShieldOld != null){
                return ResultDTOBuilder.failure("1", "已添加", null);
            }
            userShieldDAO.insert(userShieldDO);
        }
        return ResultDTOBuilder.success(userShieldDO);
    }
}
